﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;

namespace Options.IBClient.Component
{
    [Serializable]
    public class Common
    {
        #region Class Properties

        public static string IBPort
        {
            get { return GetAppSetting("Port"); }
        }

        public static string IBClientId
        {
            get { return GetAppSetting("ClientId"); }
        }

        public static string ConnectionString
        {
            get
            {

                string dataSource = string.Empty;
                string initialCatalog = string.Empty;
                dataSource = GetAppSetting("DataSource");
                initialCatalog = GetAppSetting("InitialCatalog");

                return "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog + "; Integrated Security=SSPI; Asynchronous Processing=true";
            }

        }

        public static string LogFile
        {
            get { return GetAppSetting("LogFile"); }
        }

        public static string FlatFile
        {
            get { return GetAppSetting("IchimokuFlatFile"); }
        }

        public static string Sender
        {
            get { return GetAppSetting("Sender"); }
        }

        public static string smtpclient
        {
            get { return GetAppSetting("smtpclient"); }
        }

        public static string smtpUserName
        {
            get { return GetAppSetting("smtpUserName"); }
        }

        public static string smtpPassword
        {
            get { return GetAppSetting("smtpPassword"); }
        }

        public static string[] To
        {
            get { return GetAppSetting("To").Split(';'); }
        }

        public static string[] Cc
        {
            get { return GetAppSetting("Cc").Split(';'); }
        }

        public static string[] Bcc
        {
            get { return GetAppSetting("Bcc").Split(';'); }
        }

        private static string GetAppSetting(string key)
        {
            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings[key]))
                throw new ApplicationException(string.Format("Error in '{0}': the expected configuration setting for '{1}' was not found.", "ReportConstants.GetAppSetting", key));
            return ConfigurationManager.AppSettings[key];
        }
        #endregion
    }

    #region Connection Parameters
    public class ConnectionParametersVO
    {
        #region Private Properties
        int _portNumber;
        int _clientId;
        #endregion

        #region Constructors
        public ConnectionParametersVO()
        {
            _portNumber = 7496;
            _clientId = 0;
        }

        #endregion

        #region Property Methods
        public int PortNumber
        {
            get
            {
                return _portNumber;
            }
            set
            {
                if (string.IsNullOrEmpty(value.ToString())) { _portNumber = 7496; }
                else { _portNumber = value; }
            }
        }


        public int ClientId
        {
            get
            {
                return _clientId;
            }
            set
            {
                if (string.IsNullOrEmpty(value.ToString())) { _clientId = 0; }
                else { _clientId = value; }
            }
        }

        #endregion
    }
    #endregion
}
